#!/bin/sh
#
#  install.sh
#  USAGE:  install.sh [-c]|[-l] [-s]|[-b] <cdrom_path> <install_path>
#
#  Install the binaries, fonts, libraries and header files for X11R6
#

# fail on errors
set -e

usage() {
  echo 'usage: install.x11 [-c]|[-l] [-s]|[-b] <cdrom_path> <install_path>"' >&2
  echo '       -c:  copy files' >&2
  echo '       -l:  make symbolic links instead of copying' >&2
  echo '       -s:  install for a Solaris host' >&2
  echo '       -b:  install for a SunOS 4.1.3 host' >&2
  echo '       cdrom_path: cdrom mount point (default is "/cdrom")' >&2
  echo '       install_path: installation destination (default is "/usr/X11R6")' >&2
  exit 1
}

FROM="/cdrom"
TO="/usr/X11R6"

case $# in
  1) usage;;
  2) ;;
  3) FROM=$3;;
  4) FROM=$3; TO=$4;;
  *) usage;;
esac

COPY=false
LINK=false

case $1 in
  "-c")  COPY=true;;
  "-l")  LINK=true;;
  "*") usage;;
esac


case $2 in
  "-s") MACHINE=solaris;;
  "-b") MACHINE=sun413;;
  "*") usage;;
esac

# print commands as they are executed
set -x

if test ! -d $TO ; then
	mkdir $TO
fi

if test $COPY = true ; then
	cp -rp $FROM/$MACHINE/* $TO;
	$FROM/$MACHINE/bin/lndir $TO/lib /usr/lib;
fi

if test LINK ; then
	$FROM/$MACHINE/bin/lndir $FROM/$MACHINE $TO;
	$FROM/$MACHINE/bin/lndir $TO/lib /usr/lib;
fi


exit
